/**
 * 获取系统类型
 */
import os from "os"

export default function() :any{
    let type = os.type();
    
    switch (type){
        // Linux系统
        case "Linux":{
            return {
                system:"linux",
                edition:"linux",
                digit:["x64","ppc64","arm64"].includes(process.arch)?"64":"32"
            }
        }

        // Mac系统
        case "Darwin":{
            return { 
                system: "mac",
                edition: "mac",
                digit : "64"
            }
        }

        // Windows系统
        case "Windows_NT":{
            // 判断是win7还是win10
            return getWindowsVersion()
        }
    }
    throw new Error("不支持该系统")
}





function getWindowsVersion(){
    let version = {
        "11.0":"windows11",
        "10.0":"windows10",
        "6.3":"windows8", // windows8.1
        "6.2":"windows8",
        "6.1":"windows7",
        "6.0":"windowsvista",
        "5.2":"windowsxp",
        "5.1":"windowsxp",
        "5.0":"windows2000"
    }
    let type = os.release().match(/.*?\.[\w\d]/)?.[0];

    return {
        // 遇到未知版本 默认windows10
        system:"windows",
        edition:version[type]?version[type]:"windows10",
        digit:["x64","ppc64","arm64"].includes(process.arch)?"64":"32"
    }
}